import { Map } from "immutable";
import * as actionTypes from "./constants";

const defaultState = Map({
  currentSong: {},                      //歌曲详情
  currentSongIndex: 0,                  //歌曲位置
  playList: [],                         //播放列表
  sequence: 0,                          //播放顺序  0/顺序 1/随机 2/单曲   
  lyricList: [],                        //歌词列表
  lyricIndex: 0,                         //歌词索引
  songsList: [],                        //包含歌单
  relevants: []                          //相似歌曲
});

function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.CHANGE_SONG_DETAIL: 
      return state.set("currentSong", action.currentSong);
    case actionTypes.CHNAGE_PLAY_LIST:
      return state.set("playList", action.playList);
    case actionTypes.CHNAGE_CURRENT_SONG_INDEX:
      return state.set("currentSongIndex", action.index);
    case actionTypes.CHANGE_SEQUENCE:
      return state.set("sequence", action.sequence);
    case actionTypes.CHANGE_LYRIC_LIST:
      return state.set("lyricList", action.lyricList);
    case actionTypes.CHANGE_LYRIC_INDEX:
      return state.set("lyricIndex", action.index);
    case actionTypes.CHANGE_SONGS_LIST:
      return state.set("songsList", action.songsList);
    case actionTypes.CHANGE_RELEVANT_LIST:
      return state.set("relevants", action.relevants);
    default:
      return state;
  }
}

export default reducer;